/*
 * Login para que o usuario possa fazer as configurações e logar para proceder
 * a comparação dos documentos
 */
package br.inf.acesso.view.principal;

import br.inf.acesso.regradenegocios.bancodedados.ArquivoConexao;
import br.inf.acesso.validadores.BancoDeDados;
import br.inf.acesso.view.conexao.ConfigConexao;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

/**
 * @author Douglas Giordano
 * @since 28/04/2013
 */
public class Login extends javax.swing.JFrame {

    ArquivoConexao arqSQL;
    ArquivoConexao arqFirebird;

    /**
     * Creates new form Login
     */
    public Login() {
        arqSQL = new ArquivoConexao("C:\\nQuestorEmp\\Conexao", "ConexaoQEmpresarial.txt");
        arqFirebird = new ArquivoConexao("C:\\nQuestorEmp\\Conexao", "ConexaoFirebird.txt");

        initComponents();
        this.setResizable(false);
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btConectar = new javax.swing.JButton();
        brConfigurar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/inf/acesso/icons/iconConect.png"))); // NOI18N
        btConectar.setText("Conectar");
        btConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btConectarActionPerformed(evt);
            }
        });

        brConfigurar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/inf/acesso/icons/iconConfig.png"))); // NOI18N
        brConfigurar.setText("Configurações");
        brConfigurar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                brConfigurarActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/inf/acesso/icons/iconLogin.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(82, 82, 82)
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(btConectar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                .addComponent(brConfigurar))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(57, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(67, 67, 67)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btConectar)
                    .addComponent(brConfigurar)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void brConfigurarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_brConfigurarActionPerformed
        new ConfigConexao(this, true).setVisible(true);
    }//GEN-LAST:event_brConfigurarActionPerformed

    private void btConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConectarActionPerformed
        if (arqSQL.testaConexao("com.microsoft.sqlserver.jdbc.SQLServerDriver", arqSQL.buscaConexao(), BancoDeDados.SQlServer)) {
            if (arqSQL.testaConexao("org.firebirdsql.jdbc.FirebirdDriver", arqFirebird.buscaConexao(), BancoDeDados.Firebird)) {
                new Principal().setVisible(true);
                dispose();
            }
        }
    }//GEN-LAST:event_btConectarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            javax.swing.UIManager.setLookAndFeel(new WindowsLookAndFeel());
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Login().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton brConfigurar;
    private javax.swing.JButton btConectar;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
